﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
       

        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=1;database=Blogs");

            SqlCommand cmd = new SqlCommand("select * from Users where Username='"
                + textBox1.Text.Trim() + "' and Password='" + textBox2.Text.Trim() + "'", conn);

            if (textBox1.Text == "" || textBox2.Text == "")
                MessageBox.Show("输入用户名密码");

            conn.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            sdr.Read();
            if (sdr.HasRows)
            {
                MessageBox.Show("登录成功!");
                this.Hide();
                Form2 adb = new Form2();
                adb.Show();
            }
            else
            {
                MessageBox.Show("用户名或密码错误!");
            }

            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            RegisterForm registerForm = new RegisterForm();
            registerForm.Show();


        }
    }
}
